package com.wang.lotterysystem.dao.mapper;

import com.wang.lotterysystem.dao.dataobject.activity.ActivityUserDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ActivityUserMapper {
    @Insert("<script>" +
            "insert into activity_user (activity_id, user_id, user_name, status) values " +
            "<foreach collection = 'activityUserDOList' item = 'item' index = 'index' separator = ','>" +
            "(#{item.activityId},#{item.userId},#{item.userName},#{item.status})" +
            "</foreach>" +
            "</script>")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    int batchInsert(List<ActivityUserDO> activityUserDOList);

    @Select("select *" +
            " from activity_user " +
            "where user_id = #{userId} and activity_id = #{activityId}")
    ActivityUserDO selectUserById(Long userId, Long activityId);

    @Update("update activity_user set status = #{status} " +
            "where user_id = #{userId} and activity_id = #{activityId}")
    void batchUpdateStatus(String status,Long activityId,Long userId);

    @Select("select * from activity_user " +
            "where activity_id = #{activityId}")
    List<ActivityUserDO> selectByActivityId(Long activityId);
}